package cn.doitedu.day04.adv;

import java.util.Arrays;
import java.util.List;

//作业：在MyAdvList上添加flatMap方法、reduce方法
public class MyAdvListTest {

    public static void main(String[] args) {

        MyAdvList<Integer> myList = new MyAdvList<>();
        myList.add(1);
        myList.add(2);
        myList.add(3);
        myList.add(4);
        myList.add(5);

        MyAdvList<Double> nList = myList
                .filter(in -> in % 2 == 0)
                .map(i -> i * 10.0);

//        List<Double> nList = myList.map(new MyFunction1<Integer, Double>() {
//            @Override
//            public Double apply(Integer in) {
//                return in * 10.0;
//            }
//        });

        for (Double i : nList) {
            System.out.println(i);
        }

        MyAdvList<String> myList2 = new MyAdvList<>();

        myList2.add("spark hadoop flink");
        myList2.add("spark hive flink");

//        MyAdvList<String> nList3 = myList2.flatMap(new MyFunction1<String, Iterable<String>>() {
//
//            @Override
//            public Iterable<String> apply(String in) {
//                return Arrays.asList(in.split(" "));
//            }
//        });

        MyAdvList<String> nList3 = myList2.flatMap(in -> Arrays.asList(in.split(" ")));

        for (String s : nList3) {
            System.out.println(s);
        }


        Integer r = myList.reduce(new MyFunction2<Integer, Integer, Integer>() {
            @Override
            public Integer apply(Integer i1, Integer i2) {
                return i1 + i2;
            }
        });

        System.out.println(r);
    }
}
